using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RStein.Posterous.API
{
    internal class PostTagsValueSerializer : IRequestValuesSerializer<IEnumerable<string>>
    {

        #region Constructors

        public PostTagsValueSerializer()
        {
        }

        #endregion Constructors
        
        #region Implementation of IRequestValuesSerializer<IEnumerable<string>>

        public string SerializeValue(IEnumerable<string> tags)
        {
            string result =  tags.Aggregate(new StringBuilder(), 
                                     (sb, tag) =>
                                     {
                                         sb.Append(tag);
                                         sb.Append(GlobalConstants.SITE_REQ_POST_TAGS_SEPARATOR);
                                         return sb;
                                     },
                                     sb=>
                                         {
                                             if (sb.Length > 0)
                                             {
                                                 sb.Length--;
                                             }
                                             return sb.ToString();
                                         }
                                     );

            return result;
        }

        #endregion
    }
}